<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$basic=$this->setting;
$return['basic']=$basic;
$return['setting']=$basic;
$return['banner']=$basic['hdps'];
$return['pluginset']['footernav']=$this->setting['footernav4'];
$credit_types=credit_types(true);
if($_RQ['op']=='main'){
	$_SESSION['onemerchid']=0;
	$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['uid']));
	//推荐分类
	$category=pdo_getall('jy_creditshop_category',array('uniacid'=>$_SESSION['uniacid'],'enabled'=>1,'isrecommand'=>1,'merchid'=>$_SESSION['onemerchid']),array('name','id','thumb'),'','displayorder asc');
	$return['category']=$category;
	$params=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>0,'isrecommand'=>1,'goodstype'=>0,'merchid'=>$_SESSION['onemerchid']);
	$params1=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>0,'isrecommand'=>1,'goodstype'=>1,'merchid'=>$_SESSION['onemerchid']);
	$params2=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>0,'isrecommand'=>1,'goodstype'=>2,'merchid'=>$_SESSION['onemerchid']);
	$params3=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>0,'isrecommand'=>1,'goodstype'=>3,'merchid'=>$_SESSION['onemerchid']);
	$params4=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>0,'isrecommand'=>1,'goodstype >'=>3,'merchid'=>$_SESSION['onemerchid']);
	//抽奖商品
	$cjparams=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>1,'isrecommand'=>1);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 38;
	$total='';
	//兑换商品
	$list=pdo_getslice('jy_creditshop_goods',$params,array($pindex,$psize),$total,$fields,'','displayorder asc');
	foreach($list as &$item){
			if($item['is_moretype']){
				$item['creditmore']=$item['creditmore']?json_decode($item['creditmore'],true):array();
				$item['credit']=$item['creditmore'][0]['credit'];
				$item['credit_title']=$credit_types[$item['creditmore'][0]['credit_type']];
			}else{
				$item['credit_title']=$credit_types[$item['credit_type']];
			}
	}
	$list1=pdo_getslice('jy_creditshop_goods',$params1,array($pindex,$psize),$total,$fields,'','displayorder asc');
	foreach($list1 as &$item1){
			if($item1['is_moretype']){
				$item1['creditmore']=$item1['creditmore']?json_decode($item1['creditmore'],true):array();
				$item1['credit']=$item1['creditmore'][0]['credit'];
				$item1['credit_title']=$credit_types[$item1['creditmore'][0]['credit_type']];
			}else{
				$list1['credit_title']=$credit_types[$list1['credit_type']];
			}
	}
	$list2=pdo_getslice('jy_creditshop_goods',$params2,array($pindex,$psize),$total,$fields,'','displayorder asc');
	foreach($list2 as &$item2){
			if($item2['is_moretype']){
				$item2['creditmore']=$item2['creditmore']?json_decode($item2['creditmore'],true):array();
				$item2['credit']=$item2['creditmore'][0]['credit'];
				$item2['credit_title']=$credit_types[$item2['creditmore'][0]['credit_type']];
			}else{
				$list2['credit_title']=$credit_types[$list2['credit_type']];
			}
	}
	$list3=pdo_getslice('jy_creditshop_goods',$params3,array($pindex,$psize),$total,$fields,'','displayorder asc');
	foreach($list3 as &$item3){
			if($item3['is_moretype']){
				$item3['creditmore']=$item3['creditmore']?json_decode($item3['creditmore'],true):array();
				$item3['credit']=$item3['creditmore'][0]['credit'];
				$item3['credit_title']=$credit_types[$item3['creditmore'][0]['credit_type']];
			}else{
				$item3['credit_title']=$credit_types[$item3['credit_type']];
			}
	}
	$cjlist=pdo_getslice('jy_creditshop_goods',$cjparams,array($pindex,$psize),$total,$fields,'','displayorder asc');
	if($cjlist){
		foreach($cjlist as &$itemc){
			if($itemc['is_moretype']){
				$itemc['creditmore']=$itemc['creditmore']?json_decode($itemc['creditmore'],true):array();
				$itemc['credit']=$itemc['creditmore'][0]['credit'];
				$itemc['credit_title']=$credit_types[$itemc['creditmore'][0]['credit_type']];
			}else{
				$itemc['credit_title']=$credit_types[$itemc['credit_type']];
			}
		}
	}
	$list4=pdo_getslice('jy_creditshop_goods',$params4,array($pindex,$psize),$total,$fields,'','displayorder asc');
	if($list4){
		foreach($list4 as &$item){
			if($item['is_moretype']){
				$item['creditmore']=$item['creditmore']?json_decode($item['creditmore'],true):array();
				$item['credit']=$item['creditmore'][0]['credit'];
				$item['credit_title']=$credit_types[$item['creditmore'][0]['credit_type']];
			}else{
				$item['credit_title']=$credit_types[$item['credit_type']];
			}
		}
	}
	$return['list']=$list;
	$return['list1']=$list1;
	$return['list2']=$list2;
	$return['list3']=$list3;
	$return['list4']=$list4;
	$return['cjlist']=$cjlist;
	set_html('title',$basic['title1']?'首页-'.$basic['title1']:'首页');
	$return['sharedata']=array(
		'title'=>$basic['share_title'],
		'desc'=>$basic['share_desc'],
		'link'=>custom_url('jy_juanfee/creditshop.index4/',true),
		'imgUrl'=>tomedia($basic['share_image']),
	);
	//公告列表
	$notice_list = pdo_getslice('jy_weishop_notice',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),array($pindex,20),$total,array('id','title','createtime'),'','id desc');
	if($notice_list){
		foreach($notice_list as &$notice){
			if($_SESSION['os']=='windows'){
				$notice['createtime']=date('m-d',$notice['createtime']);
			}else{
				$notice['createtime']=date('Y-m-d h:i',$notice['createtime']);
			}
		}
	}
	$return['notice_list']=$notice_list;
	$return['member']=$member;
	exi($return);
}
//获取推荐商品
if($_RQ['op']=='getlist'){
	$params=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>0,'isrecommand'=>1,'goodstype'=>0,'merchid'=>$_SESSION['onemerchid']);
	$params1=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>0,'isrecommand'=>1,'goodstype'=>1,'merchid'=>$_SESSION['onemerchid']);
	$params2=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>0,'isrecommand'=>1,'goodstype'=>2,'merchid'=>$_SESSION['onemerchid']);
	$params3=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>0,'isrecommand'=>1,'goodstype'=>3,'merchid'=>$_SESSION['onemerchid']);
	$params4=array('credit_type'=>4,'uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>0,'isrecommand'=>1,'goodstype >'=>3,'merchid'=>$_SESSION['onemerchid']);
	//抽奖商品
	$cjparams=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>1,'isrecommand'=>1,'merchid'=>$_SESSION['onemerchid']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 38;
	$total='';
	//兑换商品
	$list=pdo_getslice('jy_creditshop_goods',$params,array($pindex,$psize),$total,$fields,'','displayorder asc');
	$list1=pdo_getslice('jy_creditshop_goods',$params1,array($pindex,$psize),$total,$fields,'','displayorder asc');
	$list2=pdo_getslice('jy_creditshop_goods',$params2,array($pindex,$psize),$total,$fields,'','displayorder asc');
	$list3=pdo_getslice('jy_creditshop_goods',$params3,array($pindex,$psize),$total,$fields,'','displayorder asc');
	$list4=pdo_getslice('jy_creditshop_goods',$params4,array($pindex,$psize),$total,$fields,'','displayorder asc');
	$cjlist=pdo_getslice('jy_creditshop_goods',$cjparams,array($pindex,$psize),$total,$fields,'','displayorder asc');
	if($cjlist){
		foreach($cjlist as &$item){
			if($item['is_moretype']){
				$item['creditmore']=$item['creditmore']?json_decode($item['creditmore'],true):array();
				$item['credit']=$item['creditmore'][0]['credit'];
				$item['credit_title']=$credit_types[$item['creditmore'][0]['credit_type']];
			}else{
				$item['credit_title']=$credit_types[$item['credit_type']];
			}
		}
	}
	if($list4){
		foreach($list4 as &$item){
			if($item['is_moretype']){
				$item['creditmore']=$item['creditmore']?json_decode($item['creditmore'],true):array();
				$item['credit']=$item['creditmore'][0]['credit'];
				$item['credit_title']=$credit_types[$item['creditmore'][0]['credit_type']];
			}else{
				$item['credit_title']=$credit_types[$item['credit_type']];
			}
		}
	}
	$return['list']=$list;
	$return['list1']=$list1;
	$return['list2']=$list2;
	$return['list3']=$list3;
	$return['list4']=$list4;
	$return['cjlist']=$cjlist;
	exi($return);
}
